/*
 * Copyright 2011 Angel Sanadinov
 *
 * This file is part of VBox WMI.
 *
 * VBox WMI is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * VBox WMI is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with VBox WMI.  If not, see <http://www.gnu.org/licenses/>.
 */

package Beans.Requests.DataRetrieval;

import Utilities.Constants.VirtualResourceType;
import Utilities.PermissionsConstants;
import org.virtualbox_3_2.DeviceType;

/**
 * Instances of this class are used by the user interface when a request to
 * retrieve medium/media data is sent to the data retrieval service.
 *
 * @author Angel Sanadinov
 */
public class MediaDataRetrievalRequest extends VBoxResourceRequest
{
    private DeviceType mediumDeviceType; //the medium/media device type

    /**
     * No-argument constructor. <br><br>
     * All fields are set to their invalid values.
     */
    public MediaDataRetrievalRequest()
    {
        super();
        setRequestedAction(PermissionsConstants.ACTION_RETRIEVE_MEDIA);
        this.mediumDeviceType = DeviceType.NULL;
    }

    /**
     * Constructs a data request for a single medium, with the specified medium id.
     *
     * @param requestorId the id of the user that made the request
     * @param serverId the id of the server on which the medium resides
     * @param mediumId the id of the required medium
     * @param deviceType the device type of the medium
     */
    public MediaDataRetrievalRequest(int requestorId, int serverId, String mediumId, DeviceType deviceType)
    {
        super(requestorId, serverId, mediumId);
        setRequestedAction(PermissionsConstants.ACTION_RETRIEVE_MEDIA);
        this.mediumDeviceType = deviceType;
    }

    /**
     * Constructs a data request for all available media.
     *
     * @param requestorId the id of the user that made the request
     * @param serverId the id of the server on which the media resides
     * @param deviceType the device type of the media
     */
    public MediaDataRetrievalRequest(int requestorId, int serverId, DeviceType deviceType)
    {
        super(requestorId, serverId);
        setRequestedAction(PermissionsConstants.ACTION_RETRIEVE_MEDIA);
        this.mediumDeviceType = deviceType;
    }

    /**
     * Constructs a data request for all available media, limited by the
     * specified owner id.
     *
     * @param requestorId the id of the user that made the request
     * @param serverId the id of the server on which the media resides
     * @param ownerId the id of the media owner
     * @param deviceType the device type of the media
     */
    public MediaDataRetrievalRequest(int requestorId, int serverId, int ownerId, DeviceType deviceType)
    {
        super(requestorId, serverId, ownerId);
        setRequestedAction(PermissionsConstants.ACTION_RETRIEVE_MEDIA);
        this.mediumDeviceType = deviceType;
    }

    /**
     * Retrieves the medium/media device type associated with this request.
     *
     * @return medium/media device type
     */
    public DeviceType getMediumDeviceType()
    {
        return mediumDeviceType;
    }

    /**
     * Sets the medium/media device type for the request.
     *
     * @param mediumDeviceType the device type
     */
    public void setMediumDeviceType(DeviceType mediumDeviceType)
    {
        this.mediumDeviceType = mediumDeviceType;
    }

    /**
     * Retrieves the type of resource that is being requested.
     *
     * @return <code>VirtualResourceType.MEDIUM</code>
     */
    @Override
    public VirtualResourceType getResourceType()
    {
        return VirtualResourceType.MEDIUM;
    }

    @Override
    public boolean isValid()
    {
        if(super.isValid() && mediumDeviceType != null)
            return true;
        else
            return false;
    }

    /**
     * Returns a textual representation of the object. <br>
     *
     * It is in the form: "ClassName: (mediumId,limit,ownerId,mediumDeviceType,resourceRequestType)".
     *
     * @return the object represented as a String
     */
    @Override
    public String toString()
    {
        return MediaDataRetrievalRequest.class.getSimpleName()
                + ": (" + getResourceId() + "," + getLimit() + "," + getOwnerId() 
                + "," + mediumDeviceType + "," + getResourceRequestType() + ")";
    }
}
